<?php

namespace app\common\listener;

use app\common\helper\AliOss;
use think\Exception;

class AfterUpload
{
    public function handle($file)
    {
        // 事件监听处理
        $config = cache('config');
        if (isset($config["ali_oss_status"]) && $config['ali_oss_status'] == '启用') {
            try {
                $path = ltrim($file['path'],"/");
                $res = (new AliOss())->multiUploadFile($path,$path,$file['file_id']);
                file_put_contents('event.txt',json_encode($res),FILE_APPEND);
                return true;
            } catch (Exception $exception) {
                throwError($exception->getMessage());
            }
        } else {
            return  false;
        }
    }
}